package org.battery.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.battery.entity.Page;
import org.battery.util.PageData;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class BaseController {

	/**
	 * 得到PageData
	 */
	public PageData getPageData(){
		return new PageData(this.getRequest());
	}

	/**
	 * 得到ModelAndView
	 */
	public ModelAndView getModelAndView(){
		return new ModelAndView();
	}

	/**
	 * 得到request对象
	 */
	public HttpServletRequest getRequest() {
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();

		return request;
	}

	/**
	 * 得到response对象
	 */
	public HttpServletResponse getResponse() {
		HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
		return response;
	}

	/**
	 * 得到分页列表的信息
	 */
	public Page getPage(){

		return new Page();
	}

	public HttpSession getSession(){
		return this.getRequest().getSession();
	}

	public Object getSessionAttribute(String attribute){
		return this.getRequest().getSession().getAttribute(attribute);
	}

	public void setSessionAttribute(String attribute, Object obj){
		this.getRequest().getSession().setAttribute(attribute, obj);
	}

}
